const interceptors={
    /**
     * Determine the request status by custom code
     * Here is just an example
     * You can also judge the status by HTTP Status Code
     */
     response(response){
      const data = response.data
      // //console.log("interceptors.response:",response)
      let res=data;
      // //console.log("response config :",response.config.url)
      // //console.log("interceptors.response:",response)
      if(data.status && data.status.code ){
        
        res={
          "code": data.status.code=="ok"?0:data.status.code,
          "msg": data.status.message,
          "data":data.response
       }
      } else if(data.message){
        res={
          "code": data.code=="ok"?0:888,
          "msg": data.message,
          "data":data.response
       }
      }else if( typeof( response.msg)!="undefined" &&  typeof( response.code)!="undefined" ){
        // //console.log('typeof( data.msg)=="undefined":',response );
        res =response
      }else if( typeof( data.code)=="undefined" ){
        // //console.log('typeof( data.msg)=="undefined":',response );
        res ={
          "code": 0,
          "msg": "msg is empty!",
          "data":data
        }
      }
      return res
    },
    error(error) {
      console.error("error:", error.config, error.message);
      let response = {};
      if (error.response) {
        // The request was made and the server responded with a status code
        // that falls out of the range of 2xx
        // //console.log("error.response:",error.response.data);
        // //console.log(error.response.status);
        // //console.log(error.response.headers);
        response={
          "code":  typeof(error.response.status)=="number"?error.response.status:994,
          "msg": error.response.data,
          "data":error.response.headers
       }
        if(error.response.data && error.response.data.status && error.response.data.status.code){
          response.code =typeof(error.response.data.status.code)=="number"?error.response.data.status.code:997;
          response.msg =  error.response.data.status.message;
        }
        
      } else if (error.request) {
        // The request was made but no response was received
        // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
        // http.ClientRequest in node.js
        // //console.log("error.request:",error.request);
        
        response={
             "code": 999,
             "msg": "No Response:"+"The request was made but no response was received",
            "data":error.request
       }
      } else {
        // Something happened in setting up the request that triggered an Error
        // //console.log('Error:', error.message);
        response={
             "code": 997,
             "msg":"Something happened in setting up the request that triggered an Error:"+ error.message,
            "data":error
       }
      }
      
      return response;
      // return Promise.reject(error)
    }
 }
 module.exports =  interceptors;